<?php
	namespace Home\Controller;
	use Think\Controller;
	class SiteInfoController extends Controller{
		protected $userId;
		protected function isAuthorize(){
               $loginStatus=session('loginStatus');
               if(!$loginStatus){
                  $this->redirect('User/userLogin','',2,'not authirize');
                  exit();
                }
               $this->userId=session('id');
               $userName=session('email');
               $this->assign('userName',$userName);
               $this->assign('userId',$this->userId);			
			
		}
		
		public function index(){
			echo '2';
		}
		
		public function getSiteInfoList($page=0,$folderId=null){
			$this->isAuthorize();
			$siteInfoObj= D('SiteInfo');
			$dataList=$siteInfoObj->getSiteInfoByOwenerId($this->userId);
			print_r($dataList);
			$count=$siteInfoObj->getCountRecord($this->userId);
			$this->assign('dataList',$dataList);
		    $this->display('SiteInfoList');
			}
		
		public function addSite(){
			$this->isAuthorize();
			$folderObj= D('Folder');
			if(empty($_POST)){
				$folderList=$folderObj->getAllFolder($this->userId);
				$this->assign('folderList',$folderList);
				$this->display('Table');
				return false;
			}
			
			$siteInfoObj= D('SiteInfo');
			$siteName=$_POST['site_name'];
			$siteAddres=$_POST['site_addres'];
			$siteAccount=$_POST['site_account'];
			$sitePassword=$_POST['site_password'];
			$folderId=$_POST['folder_id'];
			$remark=$_POST['remark'];
			$status=$siteInfoObj->addSite($this->userId,$siteName,$siteAddres,$siteAccount,$sitePassword,$folderId,$remark);
			if($status>0){
			   $status=array('status'=>true,'message'=>'添加成功');
			   $this->ajaxReturn($status);
			   return false;
			}else{
			  $status=array('status'=>false,'message'=>'添加失败');
			   $this->ajaxReturn($status);
			   return false;

			}
		}
	
	
		public function deleteSite($recordId){
			$this->isAuthorize();
			$recordId=intval($recordId);
			$siteInfoObj= D('SiteInfo');
			$affectRow=$siteInfoObj->deleteSite($this->userId,$recordId);
			if($affectRow >0){
				$this->redirect('getSiteInfoList','',2,'delete ok');
				return true;
			}
			$this->redirect('getSiteInfoList','',2,'faild delete');
			return false;
			
		}
		
		public updateSiteInfo($recordId){
			$this->isAuthorize();
			if(empty($_POST)){
				$this->
			}
		}
		
		
	}